<template>
  <div class="detail-enterprise">
    <header class="add-header">
      <el-page-header content="查看企业" @back="$router.back()" />
    </header>
    <main class="add-main">
      <div class="form-container">
        <div class="title">企业信息</div>
        <div class="form">
          <el-form label-width="100px">
            <el-form-item label="企业名称：">{{ enterpriseList.name }}</el-form-item>
            <el-form-item label="法人：">{{ enterpriseList.legalPerson }}</el-form-item>
            <el-form-item label="注册地址：">{{ enterpriseList.registeredAddress }}</el-form-item>
            <el-form-item label="所在行业：">{{ enterpriseList.industryName }}</el-form-item>
            <el-form-item label="营业执照："><img :src="enterpriseList.businessLicenseUrl" width="300px" alt=""> </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="form-container">
        <div class="title">联系人信息</div>
        <div class="form">
          <el-form label-width="100px">
            <el-form-item label="企业联系人：">{{ enterpriseList.contact }}</el-form-item>
            <el-form-item label="联系电话：">{{ enterpriseList.contactNumber }}</el-form-item>
          </el-form>
        </div>
      </div>
      <div class="form-container">
        <div class="title">租赁记录</div>
        <div class="table-container">
          <el-table :data="rentList" style="width: 100%" border>
            <el-table-column type="index" label="序号" width="50" />
            <el-table-column prop="name" label="租赁楼宇" width="180" />
            <el-table-column prop="status" label="合同状态" width="180">
              <template #default="rentObj">
                <el-tag :type="tagStatus(rentObj.row.status)">{{
                  statusRent(rentObj.row.status)
                }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column label="租赁起止时间" width="280">
              <template #default="{ row }">
                {{ row.startTime }} - {{ row.endTime }}
              </template>
            </el-table-column>
            <el-table-column label="租赁合同(点击预览)">
              <template #default="{ row }">
                <el-button type="text">
                  <a :href="`${previewURL}${row.contractUrl}`" target="_blank">
                    {{ row.contractName }}
                  </a>
                </el-button>
              </template>
            </el-table-column>
            <el-table-column prop="createTime" label="录入时间" />
            <el-table-column prop="address" label="操作">
              <template #default="{ row }">
                <el-button type="text">
                  <a :href="row.contractUrl">合同下载</a>
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { getEnterpriseDetailAPI } from '@/api/Park/enterprise'
export default {
  data() {
    return {
      enterpriseList: {},
      rentList: [],
      previewURL: 'https://view.officeapps.live.com/op/view.aspx?src=' // 预览地址
    }
  },
  mounted() {
    this.getEnterpriseDetail()
  },
  methods: {
    async getEnterpriseDetail() {
      const res = await getEnterpriseDetailAPI(this.$route.params.id)
      this.enterpriseList = res.data
      this.rentList = res.data.rent
    },
    // 简化合同状态
    statusRent(status) {
      const statusMap = {
        0: '待生效',
        1: '生效中',
        2: '已到期',
        3: '已退租'
      }
      return statusMap[status]
    },
    tagStatus(status) {
      const statusMap = {
        0: 'warning',
        1: 'success',
        2: 'info',
        3: 'danger'
      }
      return statusMap[status]
    }
  }
}
</script>

<style scoped lang="scss">
.detail-enterprise {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;
      margin-bottom: 20px;

      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
      }

      .form {
        margin-bottom: 20px;
        padding: 20px 65px 24px;

        .el-form {
          display: flex;
          flex-wrap: wrap;

          .el-form-item {
            width: 50%;
          }
        }
      }
    }

    .table-container {
      padding: 20px;
    }

    .preview {
      img {
        width: 100px;
      }
    }
  }
}
</style>
